package com.student.dao.junit;

import com.student.bean.Admin;
import com.student.dao.AdminDAOImpl;
import com.student.dao.util.JDBCUtils;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.*;

class AdminDAOImplTest {

    AdminDAOImpl adminDAO = new AdminDAOImpl();

    @Test
    void register() {
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            Admin admin = new Admin("T001","123456","理工男","4113856987","123456789");
            adminDAO.register(connection,admin);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeResource(connection,null,null);
        }
    }

    @Test
    void login() {
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            Object t001 = adminDAO.login(connection, "T001", "123456");
            System.out.println(t001);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeResource(connection,null,null);
        }
    }

    @Test
    void recover(){
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            String recover = adminDAO.recover(connection, "4113856987", "123456789");
            System.out.println(recover);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeResource(connection,null,null);
        }
    }

    @Test
    void checkAdminIsExistById(){
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            boolean isExist = adminDAO.checkAdminIsExistById(connection, "T002");
            System.out.println("是否存在：" + isExist);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeResource(connection,null,null);
        }
    }

    @Test
    void checkAdminIsExistByCard(){
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            boolean isExist = adminDAO.checkAdminIsExistByCard(connection, "4113856987");
            System.out.println("是否存在：" + isExist);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeResource(connection,null,null);
        }
    }

    @Test
    void checkAdminIsExistByPhone(){
        Connection connection = null;
        try {
            connection = JDBCUtils.getConnection();
            boolean isExist = adminDAO.checkAdminIsExistByPhone(connection, "123456789");
            System.out.println("是否存在：" + isExist);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeResource(connection,null,null);
        }
    }
}